const commentService = require("../service/comment.service")

class CommentController {
  async create(ctx, next) {
    // 1. 获取 body 里面的参数
    const { content, momentId } = ctx.request.body
    const { id } = ctx.user

    // 2. 操作数据库进行存储
    const res = await commentService.create(content, momentId, id)
    ctx.body = {
      code: 0,
      message: "发表评论成功",
      data: res,
    }
  }

  async replay(ctx, next) {
    // 1. 获取 body 里面的参数
    const { content, momentId, commentId } = ctx.request.body
    const { id } = ctx.user

    // 2. 操作数据库进行存储
    const res = await commentService.replay(content, momentId, commentId, id)
    ctx.body = {
      code: 0,
      message: "回复评论成功",
      data: res,
    }
  }
}

module.exports = new CommentController()
